<? $this -> load -> view('header');?>
<script type="text/javascript" src="<?=$javscript_url;?>ajaxupload.3.5.js"></script>
<script type="text/javascript" src="<?=$javscript_url;?>jscolor.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?libraries=geometry&sensor=false"></script>
<script type="text/javascript" >
	$('#address_detail').hide();
	getDataAllData();
	$(function(){
		var btnUpload=$('#upload');
		var status=$('#status');
			new AjaxUpload(btnUpload, {
				action: '<?=$current_module;?>/uploadkml',
			name: 'uploadfile',
			onSubmit: function(file, ext){
			if (! (ext && /^(kml)$/.test(ext))){
			// extension is not allowed
				status.text('Only KML files are allowed');
				return false;
			}
			status.text('Uploading...');
			},
			onComplete: function(file, response){
				status.text('');
				if(response==="error"){
					$('<li></li>').appendTo('#files').text(file).addClass('error');
				} else{
					$('<li></li>').appendTo('#files').text("Upload Complete").addClass('success');
					$('#land_docid').val(response);
					$('#upload_kml').hide();
					$('#dataList').show();
				//	location.reload();
					getDataAllData();
				}
			}
		});
	});
	
	function saveAddress () {
		if($('#landtype').val()!="0"){
		$.post("<?=$current_module?>/save_address", { housenum: $('#housenum').val()
		, village:$('#village').val(),moono:$('#moono').val(),street:$('#street').val()
		,district:$('#district').val(),city:$('#city').val(),province:$('#province').val()
		,country:$('#country').val(),zipcode:$('#zipcode').val()
		,land_docid:$('#land_docid').val(),landtype:$('#landtype').val()
		,ownerland:$('#ownerLand').val(),landid:selectLandID },
			function(data) {
				$('#land_docid').val("");
				$('#housenum').val("");
				$('#village').val("");
				$('#moono').val("");
				$('#street').val("");
				$('#district').val("");
				$('#city').val("");
				$('#province').val("");
				$('#country').val("");
				$('#zipcode').val("");
				$('#ownerLand').val("0")
			
			//	alert(data);
				$('#address_detail').hide();
			}
		);
	}else{
		alert("กรุณาเลือกประเภทพื้นที่เพาะปลูก");
	}
	  
	}
	function backEditAddress(){
			$('#land_docid').val("");
				$('#housenum').val("");
				$('#village').val("");
				$('#moono').val("");
				$('#street').val("");
				$('#district').val("");
				$('#city').val("");
				$('#province').val("");
				$('#country').val("");
				$('#zipcode').val("");
				$('#ownerLand').val("0")
				$('#address_detail').hide();
	}
	function deleteLand (landID) {
		$.post("<?=$current_module?>/deleteLandArea", { landid:landID},
			function(data) {
				alert(data);
				// window.location.reload();
				getDataAllData();
			}
		);
	}
	
	function getDataAllData(){
		$('#content_list').html("");
		var random= Math.floor(Math.random()*11);
		$.get("<?=$current_module?>/getlastupload/"+random, function(data){
			$('#content_list').html(data);

		});
	}
	function getDataByID(addsID,seLandType){
		$('#color_map').val("000090");
		this.selectLandID = addsID;
		this.selectLandType= seLandType;
		var random= Math.floor(Math.random()*11);
		$.get("<?=$current_module?>/getAddressByID",{landid:addsID,ran:random}, function(data){
				// if(data!=null){
				$('#land_docid').val(data.land_addressid);
				$('#housenum').val(data.housenum);
				$('#village').val(data.village);
				$('#moono').val(data.moono);
				$('#street').val(data.street);
				$('#district').val(data.district);
				$('#city').val(data.city);
				$('#province').val(data.province);
				$('#country').val(data.country);
				$('#zipcode').val(data.zipcode);
				$('#address_detail').show();
			
				$('#landtype').val(data.landtypeid);
			
				$('#ownerLand').val(data.uuid);
				
				document.getElementById("iframe_map").src ="<?=$current_module.'/map/';?>"+selectLandID;
		}, "json");
	}
	var selectLandID;
	var selectLandType;
	function createMap(){
		
		document.getElementById("iframe_map").src ="<?=$current_module.'/map/';?>"+selectLandID;
		

			

		
	}
	
	
</script>
<style>
	
	
</style>
<div id="right">
	<h2><a href="#">Land:</a></h2>
	<div class="articles">
	
		<div id="upload_kml">
		<div id="upload" >
			<span>Upload KML File<span>
		</div><span id="status" ></span>
		<ul id="files" ></ul>
		</div>
		<!--	Click here: <input class="color" value="66ff00">-->
	</div>
	<div  id="address_detail" style="display: none;">
		
	
		<div id="container">
			
			
			<table width="100%" >
				<tr>
					<td width="50%">
						<table  >
							<input type="hidden" id="land_docid" name="land_docid" />
							<tr>
								<td width="200px">Housenum:</td>
								<td>
								<input type="text" name="housenum" id="housenum" />
								</td>
							
							</tr>
							<tr>
								<td>Village:</td>
								<td>
								<input type="text" name="village" id="village" />
								</td>
							</tr>
							<tr>
								<td>Moono:</td>
								<td>
								<input type="text" name="moono" id="moono" />
								</td>
							</tr>
							<tr>
								<td>Street:</td>
								<td>
								<input type="text" name="street" id="street" />
								</td>
							</tr>
							<tr>
								<td>District:</td>
								<td>
								<input type="text" name="district" id="district" />
								</td>
							</tr>
							<tr>
								<td>City:</td>
								<td>
								<input type="text" name="city" id="city" />
								</td>
							</tr>
							<tr>
								<td>Province:</td>
								<td>
								<input type="text" name="province" id="province" />
								</td>
							</tr>
							<tr>
								<td>Country:</td>
								<td>
								<input type="text" name="country" id="country" />
								</td>
							</tr>
							<tr>
								<td>Zipcode:</td>
								<td>
								<input type="text" name="zipcode" id="zipcode" />
								</td>
							</tr>
							<tr>
								<td>ประเภทพื้นที่เพาะปลูก:</td>
								<td>
									<? echo form_dropdown('landtype', $landtype, '0','id="landtype"'); ?>
									
								
								</td>
							</tr>
							<tr>
								<td>เจ้าของที่ดิน:</td>
								<td>
									<? echo form_dropdown('ownerLand', $ownerLand, '0','id="ownerLand"'); ?>
								
								</td>
							</tr>
						
							<tr>
								<td colspan="2" align="center">
								<input type="button" value="Save" onclick="saveAddress()" />
								<input type="button" value="Back" onclick="backEditAddress()" />
								
								</td>
							</tr>
					</table>
				</td>
				<td width="50%">
					<iframe id="iframe_map" width="300px" height="300px" frameBorder="0" ></iframe>
				</td>
				</tr>
				</table>
				
		
		
		
			
		</div>
	</div>
	
	<div style="clear: both;" id="content_list"></div>
</div>
<? $this -> load -> view('footer');?>